/*
day199
2020.3.14
*/ 
#include<iostream>
#include<vector>
using namespace std;

class Solution {
public:
    vector<int> sortedSquares(vector<int>& A) {
		int point=0;
		vector<int> res;
		for(;point<A.size() && A[point]<0;++point)
		{
			;
		}

		int left=point-1,right=point;
		while(left>=0 && right<A.size())
		{
			if( abs(A[left]) < A[right] )
			{
				res.push_back(A[left]*A[left]);
				left--;
			}
			else
			{
				res.push_back(A[right]*A[right]);
				right++;
			}
		}
		
		while(left>=0)
		{
			res.push_back(A[left]*A[left]);
			left--;
		}
		while(right<A.size())
		{
			res.push_back(A[right]*A[right]);
			right++;
		}
		return res;
    }
};

int main()
{
	vector<int> A={-4,-1,0,3,10};
	Solution s;
	vector<int> res=s.sortedSquares(A);
	for(auto &i:res)
	{
		cout<<i<<endl;
	}
	return 0;
}
